import type {
  BookTop30Res,
  BookTypeReadRes,
  IntegralTrendRes,
  LeaderBoardTableRes,
  ReadTimeReq,
  ReadTimeRes,
  ReadTimeTableRes,
  UserNumberRes,
} from './model';
import { requestClient } from '#/api/request';

// 接口地址枚举
enum Api {
  getBookTop30 = '/appA/top30',
  getBookTypeRead = '/appA/bookTypeRead',
  getIntegralTrend = '/appA/integralTrend',
  getLeaderBoardTable = '/appA/leaderBoardTable',
  getOrgList = '/appA/getOrgList',
  getReadTimeTable = '/appA/readTimeTable',
  getUserNumber = '/appA/numberOfUsers',
  readTimeList = '/appA/readTime',
}

// ===================== 类型声明 =====================
export interface CommonParams {
  enterpriseId?: string;
}

// ===================== 数据获取 =====================

/** 获取阅读趋势数据 */
export function getReadTime(params: ReadTimeReq & CommonParams) {
  return requestClient.post<ReadTimeRes>(Api.readTimeList, params);
}

/** 获取用户统计数据（不加 enterpriseId） */
export function getUserNumber(params: any) {
  return requestClient.get<UserNumberRes>(Api.getUserNumber, { params });
}

/** 获取受欢迎书籍top30 */
export function getTop30(params: { enterpriseId: string; orgId: string }) {
  return requestClient.get<BookTop30Res>(
    Api.getBookTop30 + '/' + params.orgId,
    {
      params: params,
    },
  );
}

/** 获取组织列表 */
export function getAllOrgList(enterpriseId?: string) {
  const params = enterpriseId ? { enterpriseId } : undefined;
  return requestClient.get<object>(Api.getOrgList, { params });
}

// ===================== 榜单/排行 =====================

/** 各类书籍阅读情况 */
export function getBooKTypeRead(orgId: string, enterpriseId?: string) {
  const params = enterpriseId ? { enterpriseId } : undefined;
  return requestClient.get<BookTypeReadRes>(`${Api.getBookTypeRead}/${orgId}`, {
    params,
  });
}

/** 各组织积分趋势图 */
export function getIntegralTrend(orgId: string, enterpriseId?: string) {
  const params = enterpriseId ? { enterpriseId } : undefined;
  return requestClient.get<IntegralTrendRes>(
    `${Api.getIntegralTrend}/${orgId}`,
    { params },
  );
}

/** 阅读时长排行榜 type 1为个人排行榜 2为组织排行榜 */
export function getReadTimeTable(type: number, enterpriseId?: string) {
  const params = enterpriseId ? { enterpriseId } : undefined;
  return requestClient.get<ReadTimeTableRes>(
    `${Api.getReadTimeTable}/${type}`,
    { params },
  );
}

/** 积分排行榜 type 1为个人排行榜 2为组织排行榜 */
export function getLeaderBoardTable(type: number, enterpriseId?: string) {
  const params = enterpriseId ? { enterpriseId } : undefined;
  return requestClient.get<LeaderBoardTableRes>(
    `${Api.getLeaderBoardTable}/${type}`,
    { params },
  );
}
